package com.wzh.bean;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		// TODO Auto-generated method stub
		// 往文件中写
		int num=(int) (Math.random()*10%5);
		System.out.println(num);
		Bean bean=new Bean();
		bean.age=22;
		bean.Nmae="name";
		bean.Password = "psw";
		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
				"result.txt"));
		out.writeObject(bean);
		out.flush();
		out.close();
		// 从文件中读
		ObjectInputStream oin = new ObjectInputStream(new FileInputStream(
				"result.txt"));
		Bean t = (Bean) oin.readObject();
		oin.close();
		System.out.println(t.toString());

	}

}
